package com.exam.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author: 黄星
 * properties文件操作
 */
public class PropertiesUtil {

	/**
	 * 根据题目类型，来获取题目数量
	 * */
	public static int getQuestionNumber(String questionType){
		Properties properties = new Properties();
		// 使用ClassLoader加载properties配置文件生成对应的输入流
		InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream("question.properties");
		// 使用properties对象加载输入流
		int number = 1;
		try {

			properties.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//获取key对应的value值
		number = Integer.parseInt( properties.getProperty( questionType + ".number" ) );
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return number;
	}

	/**
	 * 根据题目类型，来获取题目分数
	 * */
	public static int getQuestionScore(String questionType){
		Properties properties = new Properties();
		// 使用ClassLoader加载properties配置文件生成对应的输入流
		InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream("question.properties");
		int score = 1;
		// 使用properties对象加载输入流
		try {

			properties.load(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//获取key对应的value值
		score = Integer.parseInt( properties.getProperty( questionType + ".score" ) );
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return score;
	}
}
